package com.pig4cloud.pig.common.core.constant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author mobai
 */
@AllArgsConstructor
@Getter
public enum OperatorEnum {
	AND("and", " && ", " and ", "和"),
	OR("or", " || ", " or ", "或"),


	EQUAL("eq", " == ", " %s = #{params.%s} ", "等于"),
	LIKE("like", " == ", " %s like concat('%%',#{params.%s},'%%') ", "模糊"),
	LEFT_LIKE("left_like", " == ", " %s like concat('%%',#{params.%s}) ", "左模糊"),
	RIGHT_LIKE("right_like", " == ", " %s like concat(#{params.%s},'%%') ", "右模糊"),

	NOT_EQUAL("ne", " != ", " %s != #{params.%s} ", "不等于"),
	GREATER_THAN("gt", " > ", " %s > #{params.%s} ", "大于"),
	GREATER_THAN_OR_EQUAL("ge", " >= ", " %s >= #{params.%s} ", "大于等于"),
	LESS_THAN("lt", " <= ", " %s >= #{params.%s} ", "小于"),
	LESS_THAN_OR_EQUAL("le", " <= ", " %s <= #{params.%s} ", "小于等于");

	private final String type;
	private final String value;
	private final String sqlValue;
	private final String desc;

	private static final Map<String, OperatorEnum> OPERATOR_ENUM_MAP = new HashMap<>();

	static {
		for (OperatorEnum value : OperatorEnum.values()) {
			OPERATOR_ENUM_MAP.put(value.getType(), value);
		}
	}

	public static OperatorEnum getByType(String type) {
		return OPERATOR_ENUM_MAP.get(type);
	}

}
